package interceptor

import (
	"context"
	"emailcenter/utils/logx"
	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

func ErrInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
	defer func() {
		sysErr := recover()
		if sysErr != nil {
			logx.LogrusObj.Error("[RPC] ", sysErr)
			// TODO make stand error exec
			resp = nil
			err = status.Errorf(codes.Unknown, "出现一些未知错误: %v", sysErr)
		}
	}()

	return handler(ctx, req)
}
